<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/28
 * Time: 9:49
 */

namespace app\admin\controller;

use app\admin\model\AboutHelp;
use app\admin\model\AboutUs;

class About extends Base
{
    public function aboutUs(){
        $whereAA['id']=1;
        $data=AboutUs::where($whereAA)->find();
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function aboutUsForm(){
        $post=input('post.');
        $whereAA['id']=1;
        $find=AboutUs::where($whereAA)->find();
        if($find){
            $data=[
                'con_title'=>$post['con_title'],
                'con_content'=>$post['con_content']
            ];
            $save=AboutUs::where($whereAA)->update($data);
        }else{
            $data=[
                'id'=>1,
                'con_title'=>$post['con_title'],
                'con_content'=>$post['con_content']
            ];
            $save=AboutUs::insert($data);
        }
        if($save){
            return true;
        }
        return json(['msg'=>'提交失败！']);
    }
    public function aboutHelp(){
        return $this->fetch();
    }
    public function aboutHelpAjax($page,$limit){
        $data= AboutHelp::page($page,$limit)->order('con_sort desc')->select();
        $count = AboutHelp::count();
        return json(['code'=>0,'msg'=>'返回成功','count'=>$count,'data'=>$data]);
    }
    public function aboutHelpAdd(){
        return $this->fetch();
    }
    public function aboutHelpAddForm(){
        $post=input('post.');
        $data=[
            'con_title'=>$post['con_title'],
            'con_remark'=>$post['con_remark'],
            'con_sort'=>$post['con_sort'],
            'con_createtime'=>time()
        ];
        $save=AboutHelp::insert($data);
        if($save){
            return true;
        }
        return json(['msg'=>'提交失败！']);
    }
    public function aboutHelpEdit(){
        $whereAA['id']=input('get.id');
        $data=AboutHelp::where($whereAA)->find();
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function aboutHelpEditForm(){
        $post=input('post.');
        $data=[
            'con_title'=>$post['con_title'],
            'con_remark'=>$post['con_remark'],
            'con_sort'=>$post['con_sort'],
            'con_createtime'=>time()
        ];
        $whereAA['id']=$post['id'];
        $save=AboutHelp::where($whereAA)->update($data);
        if($save){
            return true;
        }
        return json(['msg'=>'提交失败！']);
    }
    public function aboutHelpDel(){
        $post=input('post.');
        $count=count($post['id']);
        for($i=0;$i<$count;$i++){
            $whereAA['id']=$post['id'][$i];
            $del=AboutHelp::where($whereAA)->delete();
        }
        if($del){
            return json(array('code'=>'success','msg'=>'删除成功！'));
        }else{
            return json(array('msg'=>'删除失败！'));
        }
    }





}